package com.system.core.qqmap;

import java.io.IOException;
import java.util.TreeMap;

import org.apache.commons.codec.digest.DigestUtils;

import com.system.core.utils.HttpUtils;

public abstract class QQMapBase {
	
	final String getway = "https://apis.map.qq.com";
	final String key = "PNDBZ-E3YRW-TSHRO-R736P-RALI2-T5FLB";
	final String sk = "XFkDbq9PsCopX5PoJ5kLoKmZdHwHmk4N";
	
	public String getService(String api,TreeMap<String, Object> params) {
		params.put("key", key);
		StringBuffer paramstr = new StringBuffer();
		params.forEach((key,value) -> {
			paramstr.append("&"+key+"="+value);
		});
		StringBuffer tmp1 = new StringBuffer(paramstr.substring(1));
		tmp1.insert(0, api+"?");
		String sig = DigestUtils.md5Hex(tmp1+sk);
		tmp1.append("&sig="+sig);
		try {
			String tmp2 = getway+tmp1.toString();
			String result = HttpUtils.get(tmp2);
			return result;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}
	

}
